﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;

namespace TriviaViews.Converters
{
    [ValueConversion(typeof(bool), typeof(Uri))]
    public class ByteToStringConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            System.Text.Encoding enc = System.Text.Encoding.ASCII;
            byte[] val = value as byte[];
            return enc.GetString(val);

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
           List<byte> result = new List<byte>();
           foreach(var c in  ((string)value).ToCharArray())
           {
               byte b = (byte)c;
               result.Add(b);
           }
            return result;
        }
    }
}
